import { mergeMap as _observableMergeMap, catchError as _observableCatch } from 'rxjs/operators';
import { from as _observableFrom, throwError as _observableThrow, of as _observableOf } from 'rxjs';
import { UserVm } from './user.model';

export class LoginVm implements ILoginVm {

    constructor(data?: ILoginVm) {
        if (data) {
            for (const property in data) {
                if (data.hasOwnProperty(property)) {
                    (<any>this)[property] = (<any>data)[property];
                }
            }
        }
    }
    username!: string;
    password!: string;

    static fromJS(data: any): LoginVm {
        data = typeof data === 'object' ? data : {};
        const result = new LoginVm();
        result.init(data);
        return result;
    }

    init(data?: any) {
        if (data) {
            this.username = data['username'] !== undefined ? data['username'] : <any>null;
            this.password = data['password'] !== undefined ? data['password'] : <any>null;
        }
    }

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data['username'] = this.username !== undefined ? this.username : <any>null;
        data['password'] = this.password !== undefined ? this.password : <any>null;
        return data;
    }
}

export interface ILoginVm {
    username: string;
    password: string;
}

export class LoginResponseVm implements ILoginResponseVm {

    constructor(data?: ILoginResponseVm) {
        if (data) {
            for (const property in data) {
                if (data.hasOwnProperty(property)) {
                    (<any>this)[property] = (<any>data)[property];
                }
            }
        }
        if (!data) {
            this.user = new UserVm();
        }
    }
    token!: string;
    user!: UserVm;

    static fromJS(data: any): LoginResponseVm {
        data = typeof data === 'object' ? data : {};
        const result = new LoginResponseVm();
        result.init(data);
        return result;
    }

    init(data?: any) {
        if (data) {
            this.token = data['token'] !== undefined ? data['token'] : <any>null;
            this.user = data['user'] ? UserVm.fromJS(data['user']) : new UserVm();
        }
    }

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data['token'] = this.token !== undefined ? this.token : <any>null;
        data['user'] = this.user ? this.user.toJSON() : <any>null;
        return data;
    }
}

export interface ILoginResponseVm {
    token: string;
    user: UserVm;
}
